package com.visualexpress.messager.fetion;

import java.awt.event.ActionEvent;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.swing.JPasswordField;

public class ReflectionUtil {
	
	public static Object invokeMtd(Object subObj,String mtdName,Object...args) throws IllegalArgumentException, InvocationTargetException
	{
		Method[] mths = subObj.getClass().getSuperclass().getDeclaredMethods();
		for(Method initialMthd :mths)
		{
			if((initialMthd.getName()).equals(mtdName))
			{
				initialMthd.setAccessible(true);
				try {
					//ActionEvent event = new ActionEvent(subObj, 554443, "initial button pressed");
					Object returnedObj = initialMthd.invoke(subObj, args);
					return returnedObj;
					
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} 
			}
			
		}
		return null;
	}
	
	public static Object getFieldValue(Object obj, String fieldname) throws NoSuchFieldException
	{
		try {
			Field field = obj.getClass().getSuperclass().getDeclaredField(fieldname);
			field.setAccessible(true);
			Object fieldValue = field.get(obj);
			return fieldValue;
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}

}
